﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Web.Security;

namespace B10.Helpers
{
    public class EmailService : B10.Helpers.IEmailService
    {
        SmtpClient _smtp;

        public EmailService()
        {
            _smtp = new SmtpClient();
            _smtp.EnableSsl = false;
        }

        public void SendVerificationEmail(MembershipUser user, string domain)
        {
            MailMessage email = new MailMessage("Juntos.pl<jun.adm@wp.pl>", user.Email);

            Guid guid = (Guid)user.ProviderUserKey;
            email.Subject = "Witamy w serwisie " + domain;
            email.IsBodyHtml = true;
            email.Body = String.Format(
                "W celu dokończenia rejestracji, kliknij proszę na poniższy link,"
                + "a Twoje konto zostanie aktywowane.<br/><br/>"
                + "Link aktywacyjny: <a href=\"http://{0}/Account/VerifyEmail/{1}\">"
                + "http://{0}/Account/VerifyEmail/{1}</a>",
                domain, guid.ToString());
            Send(email);
        }

        public void SendContact(string from, string body)
        {
            MailMessage email = new MailMessage(from, "jun.adm@wp.pl");
            email.Subject = "Kontakt";
            email.Body = body;
            Send(email);
        }

        public void Send(MailMessage message)
        {
            try
            {
                _smtp.Send(message);
            }
            catch
            {                
                //throw;
            }
        }
    }
}
